﻿/// <reference path="site.js" />

function DataJson(params) {
    this.content = null;//params.value;
    this.uri = params.uri;
    this.loaded = false;//((this.content && this.content != "undefined" && this.uri == "undefined"));

    if (typeof DataJson.initialized == "undefined") {

        // Creates the data template content from uri
        DataJson.prototype.Build = function () {
            this.loaded = false;
            var that = this;
            $.getJSON(this.uri, function (data) {
                    that.content = data;
                    that.loaded = true;
                    site.data.SynchronizeLoaded();});
        };

        DataJson.initialized = true;
    }
};

site.data = {
    items: { },
    onload: null,
    loaded: false,
    SynchronizeLoaded: function () {
        var loaded = true;
        for (var item in site.data.items) {
            loaded &= site.data.items[item].loaded;
        }

        if (loaded && !site.data.loaded) {
            site.data.loaded = true;
            if (site.data.onload != null) {
                site.data.onload();
            }
        } else {
            site.data.loaded = loaded;
        }
    }
};